﻿//
// XN4SL - Xna Framework for Silverlight.
//
using System;
using System.Collections.Generic;

namespace Xn4Sl.Framework
{
    /// <summary>
    /// A collection of game services.
    /// </summary>
    public class GameServiceContainer : IServiceProvider
    {
        private Dictionary<Type, object> services = new Dictionary<Type, object>();  
        /// <summary>
        /// Initializes a new instance of this class, which represents a collection of
        /// game services.
        /// </summary>
        public GameServiceContainer() { }
        /// <summary>
        /// Adds a service to the GameServiceContainer.
        /// </summary>
        /// <param name="type">The type of service to add.</param>
        /// <param name="provider">The service provider to add.</param>
        public void AddService(Type type, object provider) 
        {
            services.Add(type, provider);
        }
        /// <summary>
        /// Gets the object providing a specified service.
        /// </summary>
        /// <param name="type">The type of service.</param>
        /// <returns>The object providing the service.</returns>
        public object GetService(Type type) 
        {
            if(services.ContainsKey(type))
            {
                return services[type];
            }
            return null;
        }
        /// <summary>
        /// Removes the object providing a specified service.
        /// </summary>
        /// <param name="type">The type of service.</param>
        public void RemoveService(Type type) 
        {
            if (services.ContainsKey(type))
            {
                services.Remove(type);
            }
        }
    }
}
